package com.ww.springboot.boot.thread.study.executor;

import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-04-01 09:08
 */
public class Executor异常捕获1 {

    private final static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(8, 8, 8, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new CustomizableThreadFactory("test"));

    public static void main(String[] args) {
        try {
            threadPoolExecutor.execute(() -> {
                Long.valueOf("s");
            });
        } catch (Exception e) {
            //主线程无法直接捕获异常~~
            System.out.println("捕获到异常!!!!");
        }
        threadPoolExecutor.shutdown();

        try {
            Future<?> future = threadPoolExecutor.submit(() -> {
                Long.valueOf("s");
            });
            future.get();
        } catch (Exception e) {
            //主线程可以捕获异常~~
            System.out.println("捕获到异常2!!!!");
        }
        threadPoolExecutor.shutdown();

    }
}
